{extend name="admin@index_layout"/}
{block name="main"}
<link rel="stylesheet" href="__STATIC__/admin/css/cms.css">
<div class="layui-card">
    <div class="layui-card-body layui-form-pane">
        <form class="layui-form" method="post">
            <div class="layui-col-md8">
                <div class="layui-card">
                    <div class="layui-form-item">
                        <label class="layui-form-label">源语言</label>
                        <div class="layui-input-block">
                            <input type="radio" name="from" value="auto" title="中文站" checked>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">栏目推送</label>
                        <div class="layui-input-block">
                            {volist name="sites" id="vo" empty="<div class='layui-tips'>请先建站点</div>"}
                            <input type="checkbox" name="sites_cat[]" value="{$vo.id}:{$vo.mark}" lay-skin="primary" title="{$vo.name}{if $check_site && in_array($vo.id,$check_site)}[已推]{/if}" {if $check_site && in_array($vo.id,$check_site)}checked{/if}>
                            {/volist}
                        </div>
                    </div>
                    {eq name="type" value="1"}
                    <div class="layui-form-item">
                        <label class="layui-form-label">内容推送</label>
                        <div class="layui-input-block">
                            {volist name="sites" id="vo" empty="<div class='layui-tips'>请先建站点</div>"}
                            <input type="checkbox" name="page_sites[]" value="{$vo.id}:{$vo.mark}" lay-skin="primary" title="{$vo.name}{if $check_page_site && in_array($vo.id,$check_page_site)}[已推]{/if}" {if $check_page_site && in_array($vo.id,$check_page_site)}checked{/if}>
                            {/volist}
                        </div>
                    </div>
                    {/eq}
                    <div class="layui-form-item">
                        <label class="layui-form-label">重新推送</label>
                        <div class="layui-input-block">
                            <input type="radio" name="status" value="1" title="是">
                            <input type="radio" name="status" value="0" title="否" checked>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">修改时间</label>
                        <div class="layui-input-block layui-text">
                            2021-09-26
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">推送时间</label>
                        <div class="layui-input-block layui-text">
                            2021-09-26
                        </div>
                    </div>

                </div>
                {include file="cms@item_push" /}
            </div>


            <div class="layui-form-item layer-footer">
                <div class="layui-input-block">
                    <input type="hidden" name="id" value="{$catid}">
                    <button type="submit" class="layui-btn iconfont icon-send" lay-submit lay-filter="sub">推送并翻译</button>
                    <button type="reset" class="layui-btn layui-btn-primary iconfont icon-trash"> 重置</button>
                </div>
            </div>

        </form>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    layui.use(['form','yznForm','yzn','element'], function() {
        var yznForm = layui.yznForm;
        var form = layui.form;
        var element = layui.element;
        var yzn = layui.yzn;
        form.on('submit(sub)', function(data){
            var xhr = new XMLHttpRequest();
            if(!window.XMLHttpRequest){
                try {
                    xhr = new ActiveXObject("Microsoft.XMLHTTP");
                } catch(e) {}
            }
            layer.open({
                type: 1,
                title: false,
                closeBtn: 0,
                shadeClose: true,
                content: '<div style="width:400px;height:50px;padding:10px;line-height:25px;text-align:center;" id="trans"><div class="layui-progress" lay-filter="trans" lay-showPercent="yes"><div class="layui-progress-bar" lay-percent="0%"></div></div><p class="layui-progress-remark">准备就绪,开始执行</p></div>',
            });
            var oldSize=0;
            xhr.onreadystatechange = function(){
                if(xhr.readyState> 2 && xhr.readyState< 4){
                    var tmpText = xhr.responseText.substring(oldSize);
                    oldSize = xhr.responseText.length;
                    if(tmpText.length > 0 ){
                        try {
                            tmpText = JSON.parse(tmpText);
                            if (tmpText.status==-1){
                                element.progress('trans', tmpText.jindu + '%');
                                $("#trans").find(".layui-progress-remark").html(tmpText.info);
                            }
                        } catch(e) {}
                    }
                }
                if(xhr.readyState == 4){
                    try {
                        var tmpText = xhr.responseText;
                        tmpText = JSON.parse(tmpText);
                        if (tmpText.status==0){
                            layer.closeAll();
                            yzn.msg.error(tmpText.info);
                            return false;
                        }
                    } catch(e) {}
                    // 请求执行完毕
                    layer.closeAll();
                    yzn.msg.success('执行完成', function() {
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.location.reload();//刷新父页面，注意一定要在关闭当前iframe层之前执行刷新
                        parent.layer.close(index); //再执行关闭
                    });
                }
            }
            xhr.open("POST","{:url('category')}",true);
            xhr.setRequestHeader("Content-Type", "application/json");
            xhr.send(JSON.stringify(data.field));
            return false;
        })
    });
</script>
{/block}

